package com.celesea.framework.util;

/**
 * @author JackYuan
 * @create 2017-11-21 23:22
 */
public class UrlUtil {
    public static String replaces(String url, String... params) {
        String result = url;
        if (params != null && params.length > 0) {
            for (String param : params) {
                result = replace(result, param);
            }
        }
        return result;
    }

    public static String replace(String url, String param) {
        if (StringKit.isNotEmpty(param)) {
            int start = url.indexOf("{");
            int end = url.indexOf("}");
            if (start < 0 || end < 0) {
                return url;
            }
            String prefix = url.substring(0, start);
            String suffix = url.substring(end + 1);
            return prefix + param + suffix;
        }
        return url;
    }
}
